package com.sskj.mine.ui.activity;


import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.bulong.rudeness.RudenessScreenHelper;
import com.shizhefei.mvc.MVCCoolHelper;
import com.shizhefei.view.coolrefreshview.CoolRefreshView;
import com.sskj.common.adapter.slimadapter.IViewInjector;
import com.sskj.common.adapter.slimadapter.SlimAdapter;
import com.sskj.common.adapter.slimadapter.SlimInjector;
import com.sskj.common.base.App;
import com.sskj.common.box.decoration.DividerLineItemDecoration;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseActivity;
import com.sskj.lib.mvchelper.ModelRx2DataSource;
import com.sskj.mine.R;
import com.sskj.mine.R2;
import com.sskj.mine.bean.CustomListBean;
import com.sskj.mine.bean.TeamBean;
import com.sskj.mine.presenter.MyTeamActivityPresenter;
import com.sskj.mine.util.HideUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

@Route(path = RConfig.MINE_MY_TEAM)//推广明细
public class MyTeamActivity extends BaseActivity<MyTeamActivityPresenter> {
    @BindView(R2.id.tvAllNum)
    TextView tvAllNum;
    @BindView(R2.id.tvTodayNum)
    TextView tvTodayNum;
    @BindView(R2.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R2.id.coolRefreshView)
    CoolRefreshView coolRefreshView;

    @Override
    protected int getLayoutResId() {
        return R.layout.mine_activity_my_team;
    }

    @Override
    public MyTeamActivityPresenter getPresenter() {
        return new MyTeamActivityPresenter();
    }

    @Override
    protected void initView() {
        setTitle("邀请明细");
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.addItemDecoration(new DividerLineItemDecoration(this)
                .setFirstDraw(false)
                .setLastDraw(false)
                .setSecondToLastDraw(false)
                .setLeftPadding((int) RudenessScreenHelper.pt2px(App.INSTANCE, 30))
                .setRightPadding((int) RudenessScreenHelper.pt2px(App.INSTANCE, 30))
                .setDividerColor(ContextCompat.getColor(App.INSTANCE, R.color.mine_525869))
                .setPaintWidth((int) RudenessScreenHelper.pt2px(App.INSTANCE, 2)));
        SlimAdapter slimAdapter = SlimAdapter.create().register(R.layout.mine_recy_item_my_team, new SlimInjector<CustomListBean>() {
            @Override
            public void onInject(CustomListBean data, IViewInjector injector, List payloads) {
                injector.text(R.id.tvName, data.getRealname())
                        .text(R.id.tvTime, data.getReg_time())
                        .text(R.id.tvStatus, data.getLink_status() == 1 ? "邀请成功" : "未认证")
                        .text(R.id.tvAccount, TextUtils.isEmpty(data.getMobile()) ? HideUtil.getEmailHide(data.getMail()) : HideUtil.getPhoneHide(data.getMobile()));
            }
        }).attachTo(recyclerView).updateData(new ArrayList());
        ModelRx2DataSource<CustomListBean> dataSource = new ModelRx2DataSource<>((ModelRx2DataSource.OnLoadSource<CustomListBean>)
                page -> mPresenter.loadData(page), 20);
        MVCCoolHelper<List<CustomListBean>> mvcHelper = new MVCCoolHelper<>(coolRefreshView);
        mvcHelper.setDataSource(dataSource);
        mvcHelper.setAdapter(slimAdapter);
        mvcHelper.refresh();
    }

    @Override
    protected void initData() {
        mPresenter.getTitleData();
    }

    //
    public void updateTitle(TeamBean data) {
        tvAllNum.setText(data.getTotal());
        tvTodayNum.setText(data.getDay_add());
    }
}
